package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;


/**
 * 分析：
 * 问题等价于回答是否存在负权回路。正好是Bellman-Ford算法的典型应用。
 * 大致要分成两步：
 * 1、获得所有连通分支
 * 2、在每个分支中寻找负权回路
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3259 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3259.class.getResource("P3259.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		int F = Integer.valueOf(line);
		for (int i = 0; i < F; i ++){
            line = stdin.readLine();
			String[] tmp = line.trim().split(" ");
			int N = Integer.valueOf(tmp[0]);
			int M = Integer.valueOf(tmp[1]);
			int W = Integer.valueOf(tmp[2]);
			
			Edge[] edges = new Edge[2*M + W];
			for (int j = 0; j < M; j ++) {
	            line = stdin.readLine();
				tmp = line.trim().split(" ");
				int S = Integer.valueOf(tmp[0])-1;
				int E = Integer.valueOf(tmp[1])-1;
				int T = Integer.valueOf(tmp[2]);
				edges[2*j] = new Edge();
				edges[2*j].s = S;
				edges[2*j].e = E;
				edges[2*j].t = T;
				
				edges[2*j+1] = new Edge();
				edges[2*j+1].s = E;
				edges[2*j+1].e = S;
				edges[2*j+1].t = T;
			}
			for (int j = 0; j < W; j ++) {
	            line = stdin.readLine();
				tmp = line.trim().split(" ");
				int S = Integer.valueOf(tmp[0])-1;
				int E = Integer.valueOf(tmp[1])-1;
				int T = Integer.valueOf(tmp[2]);
				edges[2*M+j] = new Edge();
				edges[2*M+j].s = S;
				edges[2*M+j].e = E;
				edges[2*M+j].t = -T;
			}
			
			System.out.println(check(N, edges)?"YES":"NO");
		}
        
	}
	
	private static class Edge {
		int s;
		int e;
		int t;
	}

	private static boolean check(int N, Edge[] edges) {

		int[] d = new int[N];
		
		for (int i = 0; i < N; i ++) {
			
		}
		return false;
	}

}
